package com.qzct.controller;

import com.mybatisflex.core.paginate.Page;
import com.qzct.entity.User;
import com.qzct.entity.vo.ResultCode;
import com.qzct.entity.vo.ResultVo;
import com.qzct.utils.JwtUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.qzct.entity.Admin;
import com.qzct.service.AdminService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  控制层。
 *
 * @author 闽闽
 * @since 2024-12-07
 */
@RestController
@Api(tags = "管理员接口")
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("login")
    @ApiOperation("登录")
    public ResultVo login(@RequestBody Admin admin){
        Admin a = adminService.login(admin.getName(),admin.getPassword());
        String token = JwtUtils.generateToken(a.getId(),a.getName());
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("userinfo",a);
        return  new  ResultVo(ResultCode.LOGIN_SUCCESS,map);
    }






}
